/*
 * extension.js
 */
const IFORUM_EXTENSION_NAME = "iforum";
const IFORUM_EXTENSION_HOME = "http://www.qict.ac.cn/";

if (typeof iForumExtension == "undefined") {

	var iForumExtension = {
		_log : new Logger("iForumExtension"),

		init : function() {
			try {
				this._log.debug("> init");

				var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
						.getService(Components.interfaces.nsIProperties);
				var dir = fileLocator.get("ProfD",
						Components.interfaces.nsIFile);
				dir.append(IFORUM_EXTENSION_NAME);
				this._createDir(dir);

				this._log.debug("< init");
			} catch (e) {
				this._log.error("init directory: " + e);
			}
		},

		getName : function() {
			return IFORUM_EXTENSION_NAME;
		},

		getProfilePath : function() {
			var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
					.getService(Components.interfaces.nsIProperties);
			var profDirectory = fileLocator.get("ProfD",
					Components.interfaces.nsIFile);
			var profilepath = profDirectory.path.replace(/\\/g, "/");
			return profilepath;
		},

		getDataPath : function() {
			var dataPath = this.getProfilePath() + "/" + IFORUM_EXTENSION_NAME;
			return dataPath;
		},

		getDataDir : function() {
			var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
					.getService(Components.interfaces.nsIProperties);
			var file = fileLocator.get("ProfD", Components.interfaces.nsIFile);
			file.append(IFORUM_EXTENSION_NAME);
			return file;
		},

		_createDir : function(file) {
			if (!file.exists() || !file.isDirectory()) {
				file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
			}
		}
	}
} else {
	dump("ERROR: exist two iForumExtension !");
}